# -*- coding: UTF-8 -*-

"""allmusic URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""

import xadmin
from django.contrib import admin
from django.urls import path, include, re_path
from django.http import HttpResponse
import mysite.views
import product.views
import document.views
import download.views
import faqs.views
import link.views
import user.views
import blog.views
import message.views
import hardware.views

'''
import apps.discography.views
import apps.artists.views
import apps.songs.views
import apps.images.views
import apps.links.views
import apps.comments.views
import apps.user.views
'''

from mysite.settings import MEDIA_ROOT
from rest_framework.routers import DefaultRouter
from django.views.generic import TemplateView

#from django.conf.urls.static import static
from django.views.static import serve

#from rest_framework.authtoken import views

urlpatterns = [
    path(r'xadmin/', xadmin.site.urls),
    path(r'api-auth/',include('rest_framework.urls')),
    
    path(r'api/product-list/', product.views.list_product_item),
    path(r'api/product-list-index/', product.views.list_product_item_index),
    path(r'api/product-num/', product.views.show_product_num),
    path(r'api/chipset-list/', product.views.list_chipset),
    path(r'api/document-list/', document.views.DocumentListView.as_view(), name='document-list'),
    path(r'api/document-search/', document.views.DocumentSearchView.as_view(), name='document-search'),
    path(r'api/document-num/', document.views.show_document_num),
    path(r'api/doctype-list/', document.views.list_doctype),
    path(r'api/download-list/', download.views.DownloadListView.as_view(), name='download-list'),
    path(r'api/download-search/', download.views.DownloadSearchView.as_view(), name='download-search'),
    path(r'api/download-num/', download.views.show_download_num),
    path(r'api/restype-list/', download.views.list_restype),
    path(r'api/hardware-list/', hardware.views.HardwareListView.as_view(), name='hardware-list'),
    path(r'api/hardware-search/', hardware.views.HardwareSearchView.as_view(), name='hardware-search'),
    path(r'api/hardware-num/', hardware.views.show_hardware_num),    
    path(r'api/faqs-list/', faqs.views.FaqsListView.as_view(), name='faqs-list'),
    path(r'api/faqs-num/', faqs.views.show_faqs_num),
    path(r'api/link-list/', link.views.LinkListView.as_view(), name='link-list'),
    path(r'api/link-num/', link.views.show_link_num),
    path(r'api/blog-list/', blog.views.BlogListView.as_view(), name='blog-list'),
    path(r'api/blog-num/', blog.views.show_blog_num),
    path(r'api/show-article/', blog.views.show_article),
    path(r'api/message/', message.views.handle_message),
    path(r'api/msg-num/', message.views.show_msg_num),

    path(r'api/register/', user.views.register),
    path(r'api/modify/', user.views.modify),
    path(r'api/login/', user.views.custom_login),
    path(r'api/logout/', user.views.custom_logout),
    path(r'api/status/', user.views.check_status),
    path(r'api/user/', user.views.check_user),
    path(r'api/findpwd/', user.views.find_pwd),
    path(r'robots.txt', lambda r: HttpResponse('User-agent: *\nDisallow: /xadmin\nDisallow: /dist\nDisallow: /media', content_type='text/plain')),
    re_path('media/(?P<path>.*)', serve, {"document_root": MEDIA_ROOT}),
    path(r'', TemplateView.as_view(template_name='index.html'), name='home'),
    path(r'ueditor/', include('DjangoUeditor.urls')),   
]

# + static(settings.MEDIA_URL, document_root=MEDIA_ROOT)

#handler404 = mysite.views.page_not_found
handler404 = mysite.views.page_not_found
handler500 = mysite.views.page_error
